//
//  HomeViewController.m
//  ZYZB
//
//  Created by ENERGY on 2018/6/11.
//  Copyright © 2018年 ENERGY. All rights reserved.
//192.168.0.113:80
//http://120.78.157.132:82
#import "HomeViewController.h"
#import "HomeTableViewCell.h"
#import "InformTableViewCell.h"
#import "ProduceTableViewCell.h"
#import "DataTableViewCell.h"
#import "FunctionCollocetionViewCell.h"
#import "LMJScrollTextView2.h"
#import "ProduceCollectionViewCell.h"
#import "LoginViewController.h"
#import "SiftDetailViewController.h"
#import "InformationAnnounceViewController.h"
#define topSectionBGViewH 55/WIDTH_6_SCALE
@interface HomeViewController ()<UINavigationControllerDelegate, UITableViewDelegate, UITableViewDataSource, SDCycleScrollViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource, LMJScrollTextView2Delegate>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;//头部
@property (nonatomic, strong)UIView * footerView;//尾部
@property (nonatomic, strong)UICollectionView * functionCollocetionView;//头部下面按钮介绍
@property (nonatomic, strong)NSMutableArray * platfomAAr;//平台数据
@property (nonatomic, strong)NSMutableArray * scrollViewTextArr;//滚动文字数组
@property (nonatomic, strong)NSMutableArray * bidTypeArr;//标的种类
@property (nonatomic, strong)UIView * scrollTextView;//滚动文字模块
@property (nonatomic, strong)LMJScrollTextView2 * scrollTextUpAndDownView;//滚动条
@property (nonatomic, strong)UIView * bidSeriesView;//标的系列模块
@property (nonatomic, strong)UICollectionView * bidSeriesCollectionView;//标的系列
@property (nonatomic, strong)UIView * platformDataView;
@property (nonatomic, strong)UILabel * totalUserLab;//累计用户
@property (nonatomic, strong)UILabel * totalEarningsLab;//累计收益
@property (nonatomic, strong)UILabel * totalBidLab;//累计投标
@property (nonatomic, strong)NSMutableArray * bidSeriesArr;//标的系列
@property (nonatomic, strong)NSMutableArray * collectionCellArr;

@end

@implementation HomeViewController (Networking)
//轮播图
- (void)getCarouselData{
    [self showprogressHUD];
    NSString * timeStr = [self currentTimeStr];
    //str
    NSDictionary * dic = @{
                           @"userName":[UserModel sharedInstanced].mobile,
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{
                               @"userName":[UserModel sharedInstanced].mobile,
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/homepage/index?api=api1001"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
            NSString * compareMD5Str = [md5Code encodeStringWithDictionary:dictionary];
            NSString * signResult = [dictionary objectForKey:@"sign"];//接到的json串sign字段
            NSDictionary * jsonData = [md5Code getNSDictionaryData:dictionary];//解析为字典数据
            if ([jsonData[@"code"] isEqualToString:@"000000"]) {
                if ([jsonData[@"body"] count] > 0) {
                    if ([compareMD5Str isEqualToString:signResult]) {
                        NSMutableArray * picTemArr = [NSMutableArray array];
                        NSDictionary * picData = jsonData[@"body"];
                        for (NSDictionary * dic in picData) {
                            [picTemArr addObject:dic[@"adImg"]];
                        }
                        self.cycleScrollView.imageURLStringsGroup = picTemArr;
                        NSLog(@"成功");
                    }else{
                        NSLog(@"失败");
                    }
                }else{
                    NSLog(@"无内容");
                    ShowMessage(jsonData[@"msg"]);
                }
            }else{
                ShowMessage(jsonData[@"msg"]);
            }
            
        }
    }];
}
//平台数据
- (void)getPlatformData{
    [self showprogressHUD];
    NSString * timeStr = [self currentTimeStr];
    //str
    NSDictionary * dic = @{
                           @"userName":[UserModel sharedInstanced].mobile,
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{
                               @"userName":[UserModel sharedInstanced].mobile,
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/homepage/index?api=api1005"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
            NSString * compareMD5Str = [md5Code encodeStringWithDictionary:dictionary];
            NSString * signResult = [dictionary objectForKey:@"sign"];//接到的json串sign字段
            NSDictionary * jsonData = [md5Code getNSDictionaryData:dictionary];//解析为字典数据
            if ([jsonData[@"code"] isEqualToString:@"000000"]) {
                if ([jsonData[@"body"] count] > 0) {
                    if ([compareMD5Str isEqualToString:signResult]) {
                        self.platfomAAr = jsonData[@"body"];
                        [self.tableView reloadData];
                        NSLog(@"成功");
                    }else{
                        NSLog(@"失败");
                    }
                }else{
                    NSLog(@"无内容");
                    ShowMessage(jsonData[@"msg"]);
                }
            }else{
                ShowMessage(jsonData[@"msg"]);
            }
        }
    }];
}
//滚动文字
- (void)scrollViewAnnouncement{
    [self showprogressHUD];
    NSString * timeStr = [self currentTimeStr];
    //str
    NSDictionary * dic = @{
                           @"userName":[UserModel sharedInstanced].mobile,
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{
                               @"userName":[UserModel sharedInstanced].mobile,
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/homepage/index?api=api1002"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
            NSString * compareMD5Str = [md5Code encodeStringWithDictionary:dictionary];
            NSString * signResult = [dictionary objectForKey:@"sign"];//接到的json串sign字段
            NSDictionary * jsonData = [md5Code getNSDictionaryData:dictionary];//解析为字典数据
            if ([jsonData[@"code"] isEqualToString:@"000000"]) {
                if ([jsonData[@"body"] count] > 0) {
                    if ([compareMD5Str isEqualToString:signResult]) {
                        NSArray * tempArr  = jsonData[@"body"];
                        for (int i = 0; i<tempArr.count; i++) {
                            NSDictionary * dic = tempArr[i];
                            [self.scrollViewTextArr addObject:dic[@"infoTitle"]];
                            //                self.scrollTextUpAndDownView.textDataArr = self.scrollViewTextArr;
                        }
                        [self.tableView reloadData];
                        NSLog(@"成功");
                    }else{
                        NSLog(@"失败");
                    }
                }else{
                    NSLog(@"无内容");
                    ShowMessage(jsonData[@"msg"]);
                }
            }else{
                ShowMessage(jsonData[@"msg"]);
            }
        }
    }];
}
//首页标记接口，根据这个接口分几个section
- (void)bidTypeProduce{
    [self showprogressHUD];
    NSString * timeStr = [self currentTimeStr];
    //str
    NSDictionary * dic = @{
                           @"userName":[UserModel sharedInstanced].mobile,
                           @"phone":@"13889126201",
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{
                               @"userName":[UserModel sharedInstanced].mobile,
                               @"phone":@"13889126201",
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/homepage/index?api=api1003"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
            NSString * compareMD5Str = [md5Code encodeStringWithDictionary:dictionary];
            NSString * signResult = [dictionary objectForKey:@"sign"];//接到的json串sign字段
            NSDictionary * jsonData = [md5Code getNSDictionaryData:dictionary];//解析为字典数据
            if ([jsonData[@"code"] isEqualToString:@"000000"]) {
                if ([jsonData[@"body"] count] > 0) {
                    if ([compareMD5Str isEqualToString:signResult]) {
                        self.bidTypeArr = jsonData[@"body"];
                        [self.tableView reloadData];
                        NSLog(@"成功");
                    }else{
                        NSLog(@"失败");
                    }
                }else{
                    NSLog(@"无内容");
//                    ShowMessage(jsonData[@"msg"]);
                }
            }else{
                ShowMessage(jsonData[@"msg"]);
            }
        }
    }];
}
//标的系列
- (void)productSeriesData{
    [self showprogressHUD];
    NSString * timeStr = [self currentTimeStr];
    //str
    NSDictionary * dic = @{
                           @"t":timeStr
                           };
    //sign
    NSDictionary * signDic = @{
                               @"t":timeStr,
                               @"merchantNo":@"80d709a97af1b8ab"
                               };
    SortMD5Code * md5Code = [[SortMD5Code alloc] init];
    NSString * jsonStr = [md5Code getJsonWithStrDic:dic withSignDic:signDic];
    NSData *postData = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:@"http://120.78.157.132:82/index.php/homepage/index?api=api1004"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方式
    request.HTTPMethod = @"POST";
    //设置请求参数
    request.HTTPBody = postData;
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        [self hiddenProgressHUD];
        if (connectionError) {
            if (connectionError.code == -1001) {
                [self.view makeToast:@"请求网络超时，请稍后再试" duration:1 position:CSToastPositionCenter];
            }
        }else{
            NSDictionary *dictionary =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];//data解析为dictionary
            if (!dictionary) {
                NSLog(@"数据缺失");
                return;
            }
            NSString * compareMD5Str = [md5Code encodeStringWithDictionary:dictionary];
            NSString * signResult = [dictionary objectForKey:@"sign"];//接到的json串sign字段
            NSDictionary * jsonData = [md5Code getNSDictionaryData:dictionary];//解析为字典数据
            if ([jsonData[@"code"] isEqualToString:@"000000"]) {
                if ([jsonData[@"body"] count] > 0) {
                    if ([compareMD5Str isEqualToString:signResult]) {
                        self.bidSeriesArr = jsonData[@"body"];
                        [self.tableView reloadData];
                        NSLog(@"成功");
                    }else{
                        NSLog(@"失败");
                    }
                }else{
                    NSLog(@"无内容");
                    ShowMessage(jsonData[@"msg"]);
                }
            }else{
                ShowMessage(jsonData[@"msg"]);
            }
        }
    }];
}
@end

@implementation HomeViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.delegate = self;
    [self setStatusBarBackgroundColor:[UIColor blackColor] withAlpha:0.6];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
//    //轮播图
//    [self getCarouselData];
//    //平台数据
//    [self getPlatformData];
//    //滚动文字
//    [self scrollViewAnnouncement];
//    //首页标的
//    [self bidTypeProduce];
//    //标的系列
//    [self productSeriesData];
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"";
    
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
//    //判断当前版本方法
//    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
//    //当前版本号
//    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
//    NSLog(@"当前版本号%@",currentVersion);
//    [self judgeAppVersion];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"getFirstTitleAndSecondTitle" object:nil userInfo:@{@"firstTitleID":self.firstTitleID, @"secondTitleID":self.secondTitleID, @"secondTitle":self.secondTitle}];
}
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL isHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
}
#pragma mark - init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - TABBAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.backgroundColor = getColor(borderColor);
        _tableView.tableHeaderView = self.headerView;
        _tableView.tableFooterView = self.footerView;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[HomeTableViewCell class] forCellReuseIdentifier:NSStringFromClass([HomeTableViewCell class])];
        [_tableView registerClass:[InformTableViewCell class] forCellReuseIdentifier:NSStringFromClass([InformTableViewCell class])];
        [_tableView registerClass:[ProduceTableViewCell class] forCellReuseIdentifier:NSStringFromClass([ProduceTableViewCell class])];
        [_tableView registerClass:[DataTableViewCell class] forCellReuseIdentifier:NSStringFromClass([DataTableViewCell class])];
    }return _tableView;
}

- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
        self.cycleScrollView = [[SDCycleScrollView alloc] init];
        if (Is_Iphone_X) {
            _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 278/WIDTH_6_SCALE + 24);
            self.cycleScrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 182/WIDTH_6_SCALE + 24);
        }else{
            _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 278/WIDTH_6_SCALE);
            self.cycleScrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 182/WIDTH_6_SCALE);
        }
        _headerView.backgroundColor = [UIColor whiteColor];
        //轮播图
//        self.cycleScrollView = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 182/WIDTH_6_SCALE)];
        self.cycleScrollView.placeholderImage = [UIImage imageNamed:@"3"];
        self.cycleScrollView.delegate = self;
        self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        self.cycleScrollView.currentPageDotColor = [UIColor whiteColor];
        self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleToFill;
        self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        [_headerView addSubview:self.cycleScrollView];
        //轮播图下面view
        [self setUpHeadButton];
        //分割线
        UIView * bottomLineView = [[UIView alloc] init];
        bottomLineView.backgroundColor = getColor(grayColor);
        bottomLineView.frame = CGRectMake(0, _headerView.height - 1/WIDTH_6_SCALE, SCREEN_WIDTH, 1/WIDTH_6_SCALE);
        [_headerView addSubview:bottomLineView];
    }return _headerView;
}
//头部轮播图下按钮
- (void)setUpHeadButton{
    int collectionH = _headerView.height - self.cycleScrollView.height - 1/WIDTH_6_SCALE - 15/WIDTH_6_SCALE;
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(0, 16/WIDTH_6_SCALE, 0, 16/WIDTH_6_SCALE);
    layout.itemSize = CGSizeMake(45/WIDTH_6_SCALE, collectionH);
    layout.minimumLineSpacing = 30/WIDTH_6_SCALE;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.functionCollocetionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.cycleScrollView.height + 15/WIDTH_6_SCALE, SCREEN_WIDTH, collectionH) collectionViewLayout:layout];
    self.functionCollocetionView.delegate = self;
    self.functionCollocetionView.dataSource = self;
    self.functionCollocetionView.backgroundColor = [UIColor whiteColor];
    [self.functionCollocetionView registerClass:[FunctionCollocetionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([FunctionCollocetionViewCell class])];
    [_headerView addSubview:self.functionCollocetionView];
}

- (UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 26/WIDTH_6_SCALE)];
        _footerView.backgroundColor = getColor(borderColor);
        //警告文字
        [self bottomWarningText];
    }return _footerView;
}
//下面警告文字
- (void)bottomWarningText{
    __weak typeof (self)weakSelf = self;
    //下面文字
    UIView * topLineView = [[UIView alloc] init];
    topLineView.backgroundColor = getColor(grayColor);
    [_footerView addSubview:topLineView];
    [topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.footerView);
        make.height.mas_offset(1/WIDTH_6_SCALE);
        make.top.equalTo(weakSelf.footerView.mas_top);
    }];
    UIView * bottomLineView = [[UIView alloc] init];
    bottomLineView.backgroundColor = getColor(grayColor);
    [_footerView addSubview:bottomLineView];
    [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(weakSelf.footerView);
        make.height.mas_offset(1/WIDTH_6_SCALE);
    }];
    UILabel * warningLab = [[UILabel alloc] init];
    warningLab.text = @"市场有风险  出借需谨慎";
    warningLab.font = DEF_FontSize_10;
    warningLab.textAlignment = NSTextAlignmentCenter;
    warningLab.textColor = getColor(@"bdbdbd");
    [_footerView addSubview:warningLab];
    [warningLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.footerView);
        make.top.equalTo(topLineView.mas_bottom).mas_offset(8/WIDTH_6_SCALE);
        make.height.mas_offset(10/WIDTH_6_SCALE);
    }];
}
- (NSMutableArray *)platfomAAr{
    if (!_platfomAAr) {
        _platfomAAr = @[].mutableCopy;
    }return _platfomAAr;
}
- (NSMutableArray *)scrollViewTextArr{
    if (!_scrollViewTextArr) {
        _scrollViewTextArr = @[].mutableCopy;
    }return _scrollViewTextArr;
}
- (NSMutableArray *)bidTypeArr{
    if (!_bidTypeArr) {
        _bidTypeArr = @[].mutableCopy;
    }return _bidTypeArr;
}
- (NSMutableArray *)bidSeriesArr{
    if (!_bidSeriesArr) {
        _bidSeriesArr = @[].mutableCopy;
    }return _bidSeriesArr;
}
- (NSMutableArray *)collectionCellArr{
    if (!_collectionCellArr) {
        _collectionCellArr = @[@{@"title":@"合规运营", @"img":@"heguiyunying"},
                               @{@"title":@"资金安全", @"img":@"zijinanquan"},
                               @{@"title":@"产品特点", @"img":@"chanpintedian"},
                               @{@"title":@"信息安全", @"img":@"anquanxinxi"},
                               @{@"title":@"信息披露", @"img":@"xinxipilu"},].mutableCopy;
    }return _collectionCellArr;
}
#pragma mark - tableViewDelegate和tableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = nil;
    if (indexPath.section == self.bidTypeArr.count) {
        InformTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([InformTableViewCell class]) forIndexPath:indexPath];
        cell.model = self.scrollViewTextArr;
        return cell;
    }
    if (indexPath.section == self.bidTypeArr.count + 1) {
        ProduceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ProduceTableViewCell class]) forIndexPath:indexPath];
        cell.model = self.bidSeriesArr;
        cell.produceSeriesBlock = ^(NSString * firstTitleID, NSString * secondTitleID, NSString * secondTitle) {
            self.tabBarController.selectedIndex = 1;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"getFirstTitleAndSecondTitle" object:nil userInfo:@{@"firstTitleID":firstTitleID, @"secondTitleID":secondTitleID, @"secondTitle":secondTitle}];
        };
        [cell.collectionView reloadData];
        return cell;
    }
    if (indexPath.section == self.bidTypeArr.count + 2) {
        DataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DataTableViewCell class]) forIndexPath:indexPath];
        if (self.platfomAAr.count != 0) {
            cell.modelData = self.platfomAAr[0];
        }
        return cell;
    }else{
        HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([HomeTableViewCell class]) forIndexPath:indexPath];
        cell.model = self.bidTypeArr[indexPath.section];
        return cell;
    }return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.bidTypeArr.count + 3;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section < self.bidTypeArr.count) {
        HomeTableViewCell * cell = (HomeTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        cell.model = self.bidTypeArr[indexPath.section];
        SiftDetailViewController * siftDetailVC = [[SiftDetailViewController alloc] init];
        siftDetailVC.hidesBottomBarWhenPushed = YES;
        siftDetailVC.bidID = [cell.model objectForKey:@"selectid"];
        [self.navigationController pushViewController:siftDetailVC animated:YES];
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //灰色背景
    UIView * sectionBGView = [[UIView alloc] init];
    sectionBGView.backgroundColor = getColor(borderColor);
    int grayViewH = 13/WIDTH_6_SCALE;
    if (section < self.bidTypeArr.count) {
        sectionBGView.frame = CGRectMake(0, 0, SCREEN_WIDTH, topSectionBGViewH);
        //分割线
        UIView * topLineView = [[UIView alloc] init];
        topLineView.backgroundColor = getColor(grayColor);
        topLineView.frame = CGRectMake(0, grayViewH, SCREEN_WIDTH, 1/WIDTH_6_SCALE);
        [sectionBGView addSubview:topLineView];
        //白色背景
        UIView * whiteBGView = [[UIView alloc] initWithFrame:CGRectMake(0, topLineView.bottom, SCREEN_WIDTH, sectionBGView.height - 13/WIDTH_6_SCALE)];
        whiteBGView.backgroundColor = [UIColor whiteColor];
        [sectionBGView addSubview:whiteBGView];
        //组头标题
        int titleLabY = 15/WIDTH_6_SCALE;
        int titleLabH = whiteBGView.height - 2*titleLabY;
        UILabel * titleLab = [[UILabel alloc] initWithFrame:CGRectMake(18/WIDTH_6_SCALE, titleLabY, 100/WIDTH_6_SCALE, titleLabH)];
        titleLab.text = [self.bidTypeArr[section] objectForKey:@"title"];
        titleLab.font = DEF_FontSize_14;
        [whiteBGView addSubview:titleLab];
        //分割线
        UIView * bottomLineView = [[UIView alloc] init];
        bottomLineView.backgroundColor = getColor(grayColor);
        bottomLineView.frame = CGRectMake(0, titleLab.bottom + titleLabY, SCREEN_WIDTH, 1/WIDTH_6_SCALE);
        [whiteBGView addSubview:bottomLineView];
        //项目推荐
        UILabel * projectRecommendLab = [[UILabel alloc] init];
        projectRecommendLab.text = @"推荐项目";
        projectRecommendLab.textAlignment = NSTextAlignmentCenter;
        projectRecommendLab.textColor = getColor(@"ff8819");
        projectRecommendLab.font = DEF_FontSize_12;
        [whiteBGView addSubview:projectRecommendLab];
        [projectRecommendLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(whiteBGView.mas_right).mas_offset(-18/WIDTH_6_SCALE);
            make.centerY.equalTo(titleLab.mas_centerY);
            make.height.mas_equalTo(15/WIDTH_6_SCALE);
        }];
        //图片
        UIButton * projectImgBtn = [[UIButton alloc] init];
        [whiteBGView addSubview:projectImgBtn];
        [projectImgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(projectRecommendLab.mas_left).mas_offset(-5/WIDTH_6_SCALE);
            make.top.equalTo(projectRecommendLab.mas_top);
            make.height.mas_equalTo(14/WIDTH_6_SCALE);
            make.width.mas_equalTo(14/WIDTH_6_SCALE);
        }];
        if ([titleLab.text isEqualToString:@"福乐体验"]) {
            [projectImgBtn setImage:[UIImage imageNamed:@"fuletiyan"] forState:UIControlStateNormal];
        }else if ([titleLab.text isEqualToString:@"福乐精选"]){
            [projectImgBtn setImage:[UIImage imageNamed:@"fulejingxuan"] forState:UIControlStateNormal];
        }else{
            [projectImgBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        }
    }else{
        sectionBGView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 14/WIDTH_6_SCALE);
        //分割线
        UIView * topLineView = [[UIView alloc] init];
        topLineView.backgroundColor = getColor(grayColor);
        topLineView.frame = CGRectMake(0, grayViewH, SCREEN_WIDTH, 1/WIDTH_6_SCALE);
        [sectionBGView addSubview:topLineView];
        //白色背景
        UIView * whiteBGView = [[UIView alloc] initWithFrame:CGRectMake(0, topLineView.bottom, SCREEN_WIDTH, sectionBGView.height - 13/WIDTH_6_SCALE)];
        whiteBGView.backgroundColor = [UIColor whiteColor];
        [sectionBGView addSubview:whiteBGView];
    }
    return sectionBGView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section < self.bidTypeArr.count) {
        return topSectionBGViewH;
    }else{
        return 14/WIDTH_6_SCALE;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section < self.bidTypeArr.count) {
        return 94/WIDTH_6_SCALE;
    }
    if (indexPath.section == self.bidTypeArr.count) {
        return 54/WIDTH_6_SCALE;
    }
    if (indexPath.section == self.bidTypeArr.count + 1) {
        return 151/WIDTH_6_SCALE;
    }
    if (indexPath.section == self.bidTypeArr.count + 2) {
        return 154/WIDTH_6_SCALE;
    }return 0;
}
#pragma mark - collectionViewDelegate和collectionViewDataSource
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FunctionCollocetionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FunctionCollocetionViewCell class]) forIndexPath:indexPath];
    cell.model = self.collectionCellArr[indexPath.row];
    return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.collectionCellArr.count;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == self.collectionCellArr.count - 1) {
        InformationAnnounceViewController * vc = [[InformationAnnounceViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        LoginViewController * loginVC = [[LoginViewController alloc] init];
        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginVC];
        [self.navigationController presentViewController:navi animated:YES completion:nil];
    }
}
#pragma mark - methord
-(void)judgeAppVersion{
    //AppStore访问地址（重点）
    //trackId = 应用程序 ID;
    NSString *urlStr = @"https://itunes.apple.com//lookup?id=trackId";
    NSURL *url = [NSURL URLWithString:urlStr];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [NSURLConnection connectionWithRequest:req delegate:self];
}
#pragma mark - NSURLConnectionDataDelegate
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    NSError *error;
    //解析
    NSDictionary *appInfo = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
    NSArray *infoContent = [appInfo objectForKey:@"results"];
    //最新版本号
    NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
    NSLog(@"最新版本号%@",version);
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    //当前版本号
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    if (![version isEqualToString:currentVersion]) {
        UIAlertView *arl = [[UIAlertView alloc]initWithTitle:nil message:@"商城里面有新版本" delegate:nil cancelButtonTitle:@"YES" otherButtonTitles:nil, nil];
        [arl show];
        //trackViewUrl = 应用程序介绍网址;
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"trackViewUrl"]];
    }
}
@end
